package br.inf.solutions.apresentacoes.ssp.model.bulletin.items;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.com.vexillum.util.SpringFactory;
import br.inf.solutions.apresentacoes.ssp.control.FunctionPersonController;
import br.inf.solutions.apresentacoes.ssp.model.Person;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinItem;
import br.inf.solutions.apresentacoes.ssp.model.bulletin.BulletinTopics;
import br.inf.solutions.apresentacoes.ssp.model.hierarchy.HierarchyStructEntity;
import br.inf.solutions.apresentacoes.ssp.model.interfaces.IExistsPerson;

@Entity
@SuppressWarnings("serial")
@ValidatorClass(validatorClass = "br.inf.solutions.apresentacoes.ssp.control.validator.FunctionPersonValidator")
@Table(name = "function_person")
public class FunctionPerson extends BulletinItem implements IExistsPerson {

	@Validate(notNull = true)
	@Column(name = "begin_date", nullable = false, unique = false, updatable = false)
	private Date beginDate;

	@Validate(notNull = false)
	@Column(name = "end_date", nullable = true, unique = false, updatable = true)
	private Date endDate;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "person_id", updatable = false)
	private Person person;

	@Validate(notNull = true)
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "hierarchy_entity_id", updatable = false)
	private HierarchyStructEntity hierarchyStructEntity;
		
	public FunctionPerson() {
		super(new BulletinTopics(3l, "FunctionPerson", "/paginas/funcao/atribuirRetificacao.zul"));
	}
	
	public FunctionPerson(Person person, HierarchyStructEntity hierarchyStructEntity) {
		super(new BulletinTopics(3l, "FunctionPerson", "/paginas/funcao/atribuirRetificacao.zul"));
		this.person = person;
		this.hierarchyStructEntity = hierarchyStructEntity;
		beginDate = new Date();
	}
	
	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public HierarchyStructEntity getHierarchyStructEntity() {
		return hierarchyStructEntity;
	}

	public void setHierarchyStructEntity(
			HierarchyStructEntity hierarchyStructEntity) {
		this.hierarchyStructEntity = hierarchyStructEntity;
	}

	@Override
	public FunctionPersonController getControl() {
		return SpringFactory.getController("functionPersonController", FunctionPersonController.class, null);
	}
}